package com.zhixing.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
 * 模板自动配置
 *
 * 如果引用依赖引用了 thymeleaf 模板，请区分模板解析器
 * @author zhixing
 */
@Configuration
@ConditionalOnProperty(prefix = "swagger-2-word.thymeleaf.", value = "enable", matchIfMissing = true)
public class TemplateAutoConfig {

    @Bean
    @ConditionalOnMissingBean
    @Primary
    public ThymeleafProperties thymeleafProperties(){
        ThymeleafProperties thymeleafProperties = new ThymeleafProperties();
        thymeleafProperties.setPrefix("classpath:/templates/");
        thymeleafProperties.setSuffix(".html");
        thymeleafProperties.setCache(false);
        thymeleafProperties.setEnabled(true);
        thymeleafProperties.setEncoding(UTF_8);
        thymeleafProperties.setMode("HTML5");
        return thymeleafProperties;
    }
}
